package com.sgj.principle.inversion.improve;

/**
 * 依赖倒转原则
 * @Author: Guoji Shen
 * @Date: 2021/11/9 9:36
 */
public class DependecyInversion {
    public static void main(String[] args) {
        // 客户端无需改变
        Person person = new Person();
        person.receive(new Email());
        person.receive(new Wechat());
    }
}

/**
 * 完成 Person 接收消息的功能
 * 方式二完成
 */
class Person {
    public void receive (IReceiver receiver) {
        System.out.println(receiver.getInfo());
    }
}

interface IReceiver {
    String getInfo();
}

class Email implements IReceiver{
    public String getInfo() {
        return "电子邮件信息: hello, world";
    }
}

class Wechat implements IReceiver{
    public String getInfo() {
        return "微信信息: hello";
    }
}